<template>
	<view class="set-body">
		<input class="uni-input common-input" v-model="oldpassword" type="text" password placeholder="输入旧密码" />
		<input class="uni-input common-input" v-model="newpassword" type="text" password placeholder="输入新密码" />
		<input class="uni-input common-input" v-model="renewpassword" type="text" password placeholder="输入确认密码" />
		<button type="primary" :loading="loading" class="user-set-btn" :class="{'user-set-btn-disable':disable}" 
		@tap="submit" :disabled="disable">完成</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				oldpassword:"",
				newpassword:"",
				renewpassword:"",
				disable:true,
				loading:false
			}
		},
		watch:{
			oldpassword(val){
				this.change()
			},
			newpassword(val){
				this.change()
			},
			renewpassword(val){
				this.change()
			}
		},
		methods: {
			// 监听输入框
			change(){
				if (this.oldpassword && this.newpassword &&this.renewpassword) {
					this.disable=false;
					return;
				}
				this.disable=true;
			},
			// 验证层
			check(){
				if(!this.oldpassword || this.oldpassword==""){
					uni.showToast({
						title:"旧密码不能为空！",
						icon:"none"
					})
					return false;
				}
				if(!this.newpassword || this.newpassword==""){
					uni.showToast({
						title:"新密码不能为空！",
						icon:"none"
					})
					return false;
				}
				if(!this.renewpassword || this.renewpassword==""){
					uni.showToast({
						title:"确认密码不能为空！",
						icon:"none"
					})
					return false;
				}
				if(this.renewpassword !== this.newpassword){
					uni.showToast({
						title:"两次输入密码不一致！",
						icon:"none"
					})
					return false;
				}
				if(this.oldpassword==this.newpassword || this.oldpassword==this.renewpassword){
					uni.showToast({
						title:"新旧密码不能一样！",
						icon:"none"
					})
					return false;
				}
				
				return true;
			},
			// 提交
			submit(){
				this.loading=true;
				this.disable=true;
				if (!this.check()) {
					this.loading=false;
					this.disable=false;
					return;
				}
				// 提交服务器
				uni.showToast({
					title: '提交服务器',
					mask:false,
					duration:1500
				});
				this.loading=false;
				this.disable=false;
			}
			
			
		}
	}
</script>

<style>

</style>
